/**
 * 吃牌窗口
 * Created by duwei on 2018/4/26.
 */
var Ma_ChiPaiWindow = Window.extend({
    _blockBack: false,
    _ccsFileName :res.Ma_ChiPaiWindow_json,
    initWindow: function (arr, posibleIdxArr, paiId, callback, paiUnit) {
        this._super();
        var self = this;
        self.arr = arr;
        self.posibleIdxArr = posibleIdxArr;
        self.paiId = paiId;
        self.callback = callback;
        self.paiUnit = paiUnit;
        this._initChiPaiWindow();
    },
    _initChiPaiWindow: function () {
        var self = this;
        var root = self._nodeList['root'];
        root.getChildByName("g0").setVisible(self.posibleIdxArr.length >= 1);
        root.getChildByName("g1").setVisible(self.posibleIdxArr.length >= 2);
        root.getChildByName("g2").setVisible(self.posibleIdxArr.length >= 3);

        var fun = function (node) {
            var parentName = node.getParent().getName();
            var userData = root.getChildByName(parentName).getChildByName("1").getUserData();
            var _paiId = userData.pai;
            var paiId = userData.ori_pai_id;
            self.callback(_paiId, paiId);
            self.removeFromParent(true);
        };

        for (var i = 0; i < self.posibleIdxArr.length; i++) {
            for (var j = 0; j < 3; j++) {
                var pai = root.getChildByName("g" + i).getChildByName("" + j);
                var _paiId = self.arr[self.posibleIdxArr[i]][j];
                var paiName = self.paiUnit.getPaiNameByRowAndId(self.paiUnit.getOriginalPos(), _paiId, true, false);
                pai.setUserData({pai: _paiId, ori_pai_id: self.paiId});
                setSpriteFrameByName(pai, paiName, majiang_hn.res.pai_hn_plist);
                TouchUtil.setOnclickListener(pai, fun);
            }
        }
    }
});